/*
 * @Description: 表格相关混合组件
 * @Author: yangjiecan
 * @Date: 2020-04-15 11:34:09
 * @LastEditTime: 2020-05-26 17:51:25
 * @LastEditors: zhoujj
 */
import { getTableHeight } from '../utils/utils'
const mixin = {
    data () {
        return {
            tableHeight: null, // 表格高度
            hegihtNum: null,
            isShow: true, // 查询条件是否张开(需要展开收起改为false)
            showTxt: '展开',
            currentRows: [],
            currentIds: []
        }
    },
    computed: {},
    methods: {
        getRowsData (rows) { // 获取选中行数
            this.currentRows = rows
            this.currentIds = this.currentRows.map(row => row && row.id)
        },
        getheihgt () { // 动态识别表格高度
            this.tableHeight = getTableHeight('.header-box', '.filter', '.footer-btn')
            this.hegihtNum = document.querySelector('.filter').clientHeight
            let resizeTimer = null
            let that = this
            window.addEventListener('resize', () => {
                if (resizeTimer) clearTimeout(resizeTimer)
                resizeTimer = setTimeout(function () { // 防抖节流
                    // 表格高度
                    that.tableHeight = getTableHeight('.header-box', '.filter', '.footer-btn')
                    that.hegihtNum = document.querySelector('.filter').clientHeight
                }, 200)
            })
        },
        // 展开收缩
        tabHeihgt () {
            let that = this
            this.isShow = !this.isShow
            if (this.isShow) {
                this.showTxt = '展开'
            } else {
                this.showTxt = '收起'
            }
            this.$nextTick(() => {
                that.tableHeight = getTableHeight('.header-box', '.filter', '.footer-btn')
                if (this.$refs.elTable) {
                    this.$refs.elTable.getheihgt()
                }
            })
        }
    },
    mounted () {
        this.getheihgt()
        this.getTableData()
        // console.log('---getTableHeight', getTableHeight())
    }
}
export default mixin
